#/usr/bin/bash
echo "init zookeeper config"
cp ./zoo.cfg ./zoo-1.cfg

for i in {1..4}; do
  cp ./zoo.cfg ./zoo-${i}.cfg
  # shellcheck disable=SC2129
  echo "clientPort=218${i}" >>./zoo-${i}.cfg
  echo "dataDir=/root/tool/zookeeper/data/zk${i}" >>./zoo-${i}.cfg
  echo "server.1=127.0.0.1:2001:3001:participant" >>./zoo-${i}.cfg
  echo "server.2=127.0.0.1:2002:3002:participant" >>./zoo-${i}.cfg
  echo "server.3=127.0.0.1:2003:3003:participant" >>./zoo-${i}.cfg
  echo "server.4=127.0.0.1:2004:3004:observer" >>./zoo-${i}.cfg
  mkdir "./data/zk${i}" -p && echo "${i}" >>./data/zk${i}/myid
done

echo "move zookeeper conf"
mv zoo-*.cfg ./conf

echo "zookeeper start"

for i in {1..4}; do
  ./bin/zkServer.sh start conf/zoo-${i}.cfg
done

for i in {1..4}; do
  ./bin/zkServer.sh status conf/zoo-${i}.cfg
done
